


var UIManage = require("UIManage");
var FileServe = require("FileServe");
const ADSdk = require("ADSdk");
cc.Class({
    extends: require("BasePopUI"),

    properties: {
        BtnSeeVideo:cc.Node,
        // BtnShare:cc.Node,
        _action : null,
        DiamondLabel: cc.Label
    },
    
    onLoad()
    {
        this._super();
        this.childrenRankCom = cc.find("wx").getComponent("ChildrenRank");
        this.GameInitCom = cc.find("Canvas").getComponent("GameInit");

        this.DiamondLabel.string = this.GameInitCom.PopsList.Diamond;
    },

    start()
    {
       
    },

    onEnable()
    {

    },

    Close()
    {
        this.Mask.active = false;
        var s = cc.scaleTo(0.2,0.1);
        var call = cc.callFunc(function()
        {
            this.node.active = false;
        }.bind(this));
        this.node.runAction(cc.sequence(s,call));
        if(this._action!=null)
        {
            this._action();
            this._action = null;
        }
    },

    BtnVideo() 
    {
        var Count = FileServe.Instance.GetDimondVideoCount();
        if(Count == -1)
        {
            // TODO TOAST 今日次数用尽
            UIManage.Instance.ShowToast("今日次数用尽");
        }
        else {
            var self = this;
            //看视频...奖励5个钻石
            // TODO 广告 视频 获得星星x30
            ADSdk.showVideo(null, (result) => {
                if (result == 1) {
                    self.getDimond(Count);
                }
            })
            
        }

    },

    getDimond(count)
    {
        if(UIManage.Instance.SceneState == "Gaming")
        {
            var FactoryItem = require("FactoryItem");
            FactoryItem.Instance.UIMianCom.UserDiamond(50); 
        }
        else if(UIManage.Instance.SceneState =="Start")
        {
            this.GameInitCom.PopsList.Diamond+=50;
            
            UIManage.Instance.Starting.getComponent("UIStart").SetDiamond();
        }
        this.DiamondLabel.string = this.GameInitCom.PopsList.Diamond;
        this.Close();
        count--;
        cc.sys.localStorage.setItem("DimondCount",count);
        
    },


});
